var vm = new Vue({
    //vue对象节点,指向父盒子
    el:'#lost',                                                                   
    //vue实例 的data属性
    data:function(){
        return{
          pageA:true,
          pageB:false,
          pageC:false,
          tname:'',
          createUser:'',
          createDate:[],
	      tableData:[],
	      newFlag:false,
	      //分页条
	      pageSize:10,
	      currPage:1,
	      total:1,
	      lostEditorEdit:null,
	      //
	      lostTopic:{},
	      lostTopicRules:{ 
	    	  tname: [{ required: true, message: '请填写主题', trigger: 'blur' }],
	    	  //tcontent: [{ required: true, message: '请填写帖子内容', trigger: 'blur' }]
	      },
	      //帖子详情
	      topic:{},
	      topicV:false,
	      topicData:{
	    	  "user":{},
	    	  "plate":{}
	      }
        };
    },
    //vue实例 的methods
    methods:{
       handleSizeChange:function(val) {
          vm.pageSize = val;
          vm.loadData();
       },
       handleCurrentChange:function(val) {
    	   vm.currPage = val;
    	   vm.loadData();
       },
       //格式化日期
       dateFormat:function(row,column){
    	   var date = row[column.property];
    	   if(date == undefined){
    		   return "";
    	   }
    	   return moment(date).format("YYYY-MM-DD HH:mm:ss");
       },
       loadData:function(){
    	   vm.lostEditorEdit = UM.getEditor("lostEditorEdit");
    	   $('.edui-container').css("width","");
    	   $('.edui-container').css("height","600px");
    	   $('.edui-body-container').css("width","");
    	   var url = "./listTopic.action";
    	   if(vm.createDate == null || vm.createDate.length ==0 
    			   || typeof(vm.createDate[0]) == 'string' || typeof(vm.createDate[1]) == 'string'){
    		   vm.createDate = ['',''];
		   }else{
			   vm.createDate.splice(0,2,moment(vm.createDate[0]).format('YYYY-MM-DD'),
			   moment(vm.createDate[1]).add(1, 'days').format('YYYY-MM-DD'));
		   };
    	   var params = {
    			"pagemap.pname":"失物板块",
    			"pagemap.page":vm.currPage,
                "pagemap.size":vm.pageSize,
                "pagemap.userCode":vm.createUser,
                "pagemap.tname":vm.tname,
                'pagemap.mindate':vm.createDate[0],
     		    'pagemap.maxdate':vm.createDate[1]
    	   }
    	   pb.ajaxPost(url,params,function(r){
	       		if(r.code == '000000'){
	       			vm.tableData = r.topicList;
	       			var nowDate = new Date().getTime();
	       			if(vm.tableData !== null && vm.tableData.length>0){
	       				for(var i=0;i<vm.tableData.length;i++){
	       					var tempDate = new Date(vm.tableData[i].t_create_time).getTime();
	       					vm.tableData[i].flag = nowDate - tempDate > (1 * 3600 * 1000 * 24)?0:1;
	       					
	       					vm.lostEditorEdit.setContent(vm.tableData[i].tcontent);
	       					vm.tableData[i].tcontent = vm.lostEditorEdit.getContentTxt();
		       			}
	       			}
	       			vm.lostEditorEdit.setContent('');
	       			vm.total = r.topiccount;
	       		}else{
               		pb.alertErr("加载失败");
               	}
	       },function(err){
	    	   pb.alertErr("加载失败");
	       });
       },
       query:function(){
    	   vm.loadData();
       },
       getRecord(tid){
    	   var url = "./getTopicById.action";
    	   var params = {
    		   'topic.tid':tid
    	   }
    	   pb.ajaxPost(url,params,function(r){
	       		if(r.code == '000000'){
	       			vm.topicData = r.topic;
	       			vm.lostEditorEdit.setContent(vm.topicData.tcontent);
	       			vm.topicData.createDate = moment(vm.topicData.t_create_time).format('YYYY-MM-DD');
	       			vm.topicData.tcontent = vm.lostEditorEdit.getContent();
	       			$('#content').append(vm.topicData.tcontent);
	       			//vm.lostEditorEdit.setContent('');
	       		}else{
	       		 pb.alertErr('获取信息失败');
	       		}
	       },function(err){
	    	   pb.alertErr('获取信息失败');
	       });
       },
       open(tid){
    	   /*$('#content').empty();
    	   vm.topicV = true;
    	   vm.getRecord(tid);*/
    	   window.parent.vm.goTo('viewTopic',tid);
       },
       //发帖
       add:function(){
    	   vm.pageA=false;
    	   vm.pageB=true;
    	   vm.pageC=false;
    	   
       },
       submit:function(formName){
    	   vm.$refs[formName].validate(function(valid) {
 	          if (valid) {
	                  var url = './addTopic.action';
	                  var params = {
	                		"topic.plate.pid":1,
	                  		"topic.tname":vm.lostTopic.tname,
	                  		"topic.tcontent":vm.lostEditorEdit.getContent()
	                  };
	                  
	                  pb.ajaxPost(url,params,function(r){
	                  	if(r.code == '000000'){
	                  		pb.alertSuc("发表成功");
	                  		vm.back('lostTopicRef');
	                  	}else{
	                  		pb.alertErr("发表失败");
	                  	}
	                  	},function(err){

	                  		pb.alertErr("操作超时");
	                  	});
 	          } else {
 	            return false;
 	          }
    	  });
       },
       back:function(formName){
    	   vm.pageA=true;
    	   vm.pageB=false;
    	   vm.pageC=false;
    	   vm.$refs[formName].resetFields();
    	   vm.lostTopic = {};
    	   vm.lostEditorEdit.setContent('');
    	   vm.query();
       }


    }
    //vue实例 的methods结束
});
vm.loadData();